package com.coursebooking.repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.coursebooking.model.Teacher;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.Optional;

@Mapper
public interface TeacherRepository extends BaseMapper<Teacher> {
    
    @Select("SELECT * FROM teacher WHERE email = #{email}")
    Teacher selectByEmail(String email);
    
    @Select("SELECT COUNT(*) FROM teacher WHERE email = #{email}")
    int countByEmail(String email);
    
    // 为了保持兼容性，添加包装方法
    default Optional<Teacher> findByEmail(String email) {
        return Optional.ofNullable(selectByEmail(email));
    }
    
    default boolean existsByEmail(String email) {
        return countByEmail(email) > 0;
    }
}